home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 013 / ldir30.arc / LDIR30.ASM next >
Encoding:
Assembly Source File  |  1986-06-04  |  25.2 KB  |  1,281 lines

  1.     Page    80,132
  2.     Title    --- LDIR - List    DIRectory - Version 3.0    ---
  3.  
  4.     ;    List Entire Directory
  5.  
  6. DtaNtry    Struc                ;File entry
  7. DtaRsvd    Db    21 Dup (0)        ; reserved
  8. DtaAttr    Db    0            ; attribute
  9. DtaTime    Dw    0            ; update time
  10. DtaDate    Dw    0            ; update date
  11. DtaSize    Dw    0,0            ; size bytes (lo,hi)
  12. DtaName    Db    12 Dup (' ')        ; name and ext
  13.     Db    0,13,10,255        ; stopper and print
  14. DtaNtry    Ends
  15.  
  16. ArgNtry    Struc                ;Search    arguments
  17. ArgDriv    Db    0,':'            ; drive
  18. ArgPath    Db    '\'            ; path delimiter
  19. ArgName    Db    64 Dup (0),255        ; path,file,ext
  20. ArgNtry    Ends
  21.  
  22. TblNtry    Struc                ;Table Entries
  23. TblAttr    Db    0            ; attribute
  24. TblPath    Db    21 Dup (0)        ; path name(s)
  25. TblName    Db    8 Dup (' ')        ; file name
  26. TblDot    Db    ' '            ; delimiter
  27. TblExt    Db    3 Dup (' ')        ; extension
  28. TblSize    Db    ' 0000000 '        ;File size
  29. TblDate    Db    '80-01/01 '        ;Date
  30. TblTime    Db    ' 0:00 '        ;Time
  31. TblFatr    Db    3 Dup (' ')        ;File attributes
  32. TblCtl    Db    13,10,255
  33. TblNtry    Ends
  34.  
  35.  
  36. Cseg    Segment    Public Para 'CODE'
  37.     Assume    CS:Cseg,DS:Cseg,ES:Cseg
  38.     Org    100h
  39. Ldir    Proc    Far
  40.     Mov    Stackx,SP        ;Save stack ptr    for exiting
  41.     Jmp    Start
  42.     Page
  43. ;
  44. ;    Data Areas, Constants, Etc.
  45.  
  46. Dta_Len    Equ    Size DtaNtry        ;DTA length
  47. Arg_Len    Equ    Size ArgNtry        ;Argument length
  48. Tbl_Len    Equ    Size TblNtry        ;Disk record entry
  49.  
  50. Depth    Equ    3            ;Maximum sub-DIR nest level
  51. TAB    Equ    9
  52. LF    Equ    10
  53. CR    Equ    13
  54. Stopper    Equ    255            ;Ends print strings
  55.  
  56. CURDSK    Equ    19h            ;Get current disk
  57. SETDTA    Equ    1Ah            ;Set data transfer area
  58. DSKSPC    Equ    36h            ;Get disk free space
  59. CHDIR    Equ    3Bh            ;Change    directory
  60. WRITE    Equ    40h            ;Write to a file handle
  61. GETPATH    Equ    47h            ;Get current directory
  62.  
  63. Stackx    Dw    0            ;Entry stack pointer
  64. DirMask    Db    0            ;Directory flags mask
  65. Errlvl    Db    0            ;DOS return code
  66. _Attr    Db    7            ;Clear attribute
  67. _Page    Db    0            ;Video page
  68.  
  69. Flags    Db    ByName            ;Command switches
  70.  ByAttr     Equ    1            ;-attributes included
  71.  ByHide     Equ    2            ;-want hidden files
  72.  ByClear Equ    4            ;-clear    screen
  73.  ByDate     Equ    8            ;-sort by date/time
  74.  ByExt     Equ    10h            ;-sort by extension
  75.  ByName     Equ    40h            ;-sort by name
  76.  BySize     Equ    80h            ;-sort by size
  77.  
  78. Flags2    Db    0            ;More switches
  79.  ByMod     Equ    01h            ;-modified files only
  80.  ByWait     Equ    02h            ;-wait when screen full
  81.  ByBrief Equ    4            ;-four up
  82.  ByPath     Equ    20h            ;-all paths
  83.  
  84. Date    Record    Yr:7,Mo:4,Dy:5        ;Packed    date
  85. Time    Record    Hour:5,Min:6,Sec:5    ;Packed    time
  86.  
  87. AnyName    Db    '\????????.???',0,Stopper ;Global filename.ext
  88. Blanks    Db    22 Dup (' ')
  89. Subdir    Db    '-Dir'
  90.  
  91. Count    Dw    0            ;Number    of files
  92. NumDir    Dw    0            ;Number    of table entries
  93. MaxDir    Dw    0            ;Maximum table entries
  94. NxtDir    Dw    0            ;Offset    to next    entry
  95. PtrDir    Dw    0            ;Offset    to first entry
  96. SegDir    Dw    0            ;Seg addr of table
  97. NumByte    Dw    0,0            ;Total bytes used
  98. Linecnt    Db    0            ;Line counter for /W
  99.  
  100. NumRec    Dw    0            ;Number    of entries
  101. Loc    Dw    0
  102. Index1    Dw    0
  103. Incr    Dw    0
  104. Limit    Dw    0
  105. Index2    Dw    0
  106. Ptr1    Dw    0            ;Offset    to record Index1
  107. Ptr2    Dw    0            ;Offset    to record Index2
  108.  
  109. KeyPtr    Dw    0            ;Offset    to key
  110. KeyLen    Dw    0            ;Length    of key
  111. Base    Dw    0            ;Seg addr of array
  112.     Page
  113. ;
  114. ;    Headings and titles
  115.  
  116. Titlea    Db    'List DIRectory            Volume: '
  117. VolName    Db    11 Dup (' '),11    Dup (' ')
  118. Month    Db    'mm/'
  119. Day    Db    'dd/'
  120. Year    Db    'yy '
  121. Hours    Db    'hh:'
  122. Mins    Db    'mm:'
  123. Secs    Db    'ss',CR,LF,Stopper
  124.  
  125. More    Db    '... more',Stopper
  126.  
  127. Titleb    Db    TAB,TAB,TAB,TAB,'  '    ;Command parameters
  128. Titles    Db    64 Dup (0),Stopper    ;Current directory
  129.  
  130. Titlec    Db    CR,LF,'Filename Ext   Bytes  -Last Change-     '
  131. Titled    Db    'Filename Ext   Bytes  -Last Change-'
  132. Newline    Db    Cr,Lf,Stopper
  133. NrMsg    Db    Cr,Cr,2    Dup (' ')    ;Ending    message
  134. NrBytes    Db    '       0 bytes in'
  135. NrFiles    Db    '       0 File(s);  '
  136. NrSize    Db    '       0 bytes free.',Stopper
  137.     Page
  138.  
  139. ExtFCB    Db    255,0,0,0,0,0        ;Extended FCB to get label
  140.     Db    8            ;Attribute
  141. DriveNr    Db    0,11 Dup('?')        ;Drive number
  142.     Db    2 Dup(0)        ;Current block number
  143.     Db    3 Dup(0)        ;Logical record    size
  144.     Db    20 Dup(0)        ;File size
  145.  
  146. ParmDr    Db    ' :'            ;Drive letter
  147. ParmDir    Db    64 Dup (0)        ; for specific path
  148.  
  149. Temp    Db    0            ;Sort exchange area
  150. OrigDr    Db    'x:'            ;Original drive
  151. OrigDir    Db    '\',63 Dup (0)        ; and path
  152. OrigPtr    Dw    OrigDir            ;End of    orig path name
  153.  
  154. RootDir    Db    'x:\',0            ;To get    vol label
  155. OldDate    Db    8 Dup (0)
  156. DrPtr    Dw    Offset ParmDr
  157. Model    TblNtry    <>            ;Model print line
  158.     Page
  159. ;
  160. ;    Set default drive and path
  161.  
  162. Start:
  163.     Mov    AH,8            ;Get monitor stuff
  164.     Int    10h
  165.     Mov    _Page,0
  166.     Mov    _Attr,AH
  167.  
  168.     Call    Switchs            ; Get program options
  169.  
  170.     Mov    AH,13            ; Reset    diskettes
  171.     Int    21h
  172.  
  173.     Mov    AH,CURDSK        ; Get current disk
  174.     Int    21h
  175.     Add    AL,'A'
  176.     Mov    OrigDr,AL        ; Save original    drive letter
  177.     Mov    RootDir,AL        ;  for reading vol label
  178.     Mov    ParmDr,AL
  179.  
  180.     Mov    DX,Offset DTA        ; Set Data Transfer Area
  181.     Mov    AH,SETDTA
  182.     Int    21h
  183.  
  184.     Mov    CX,Offset Table        ; Clear    work areas
  185.     Mov    DI,Offset Entry
  186.     Sub    CX,DI
  187.     Mov    AL,0
  188.     Rep    Stosb
  189.  
  190.     Call    GetParm            ; Get desired dr:path
  191.  
  192.     Call    GetVol            ; Get volume name
  193.  
  194.     Call    SetArg            ; Set search argument
  195.  
  196.     Call    Alloc            ; Allocate table for directory
  197.  
  198.     Call    Clock            ; Date/time to heading
  199.  
  200.     Call    GetDir            ; Read the directory
  201.  
  202.     Test    Flags,255        ; Any sort options?
  203.     Jz    NoSort            ; no, display fifo dir
  204.     Call    Sort            ; Sort directory table
  205.  
  206. NoSort:
  207.     Call    Print            ; Display the entries
  208.  
  209.     Mov    AX,Count        ; Number of files
  210.     Sub    DX,DX
  211.     Mov    SI,Offset NrFiles
  212.     Call    Format
  213.  
  214.     Mov    DX,NumByte        ; Total    bytes used
  215.     Mov    AX,NumByte+2
  216.     Mov    SI,Offset NrBytes
  217.     Call    Format
  218.  
  219.     Mov    DX,Offset NrMsg
  220.  
  221. Exit:    Mov    SP,Stackx        ;Insure    exiting    stack
  222.     Call    PrintS            ;Display final message
  223.  
  224. Done:    Mov    AL,Errlvl        ;Return    to system
  225.     Mov    AH,4Ch            ; via EXIT
  226.     Int    21h
  227.  
  228. Ldir    Endp
  229.  
  230.     Page
  231. ;
  232. ;    Set options from command line
  233.  
  234. Switchs    Proc    Near
  235.     Mov    SI,82h            ; Command tail
  236.     Mov    DH,Flags        ; Default switches
  237.     Mov    DL,Flags2
  238.     Sub    CX,CX
  239.     Or    CL,Byte    Ptr -2[SI]    ; test parm length
  240.     Jz    Switch_Exit        ; none,    return as-is
  241.  
  242. Sw1:    Lodsb                ; Scan for switch
  243.     Cmp    AL,'/'
  244.     Loopne    Sw1
  245.     Or    CX,CX            ; found    one?
  246.     Jz    Switch_Exit
  247.     Mov    Byte Ptr -1[SI],CR    ; Stop string here
  248.     Jmp    Short Sw2a
  249.  
  250. Switch_Exit:
  251.     Mov    Flags,DH        ; Store    new switches
  252.     Mov    Flags2,DL
  253.  
  254.     Mov    AL,DirMask        ; Current directory attribute mask
  255.     Test    Flags,ByHide        ;  include hidden files
  256.     Jz    Swx1
  257.     Or    AL,2
  258. Swx1:    Test    Flags,ByAttr        ;  include display of attributes?
  259.     Jz    Swx2
  260.     Or    AL,7
  261. Swx2:    Test    Flags2,ByPath        ;  include sub-directories?
  262.     Jz    Swx3
  263.     Or    AL,16
  264. Swx3:    Mov    Byte Ptr DirMask,AL    ; Update dir search criteria
  265.     Ret
  266.  
  267. Sw2:    Lodsb
  268.     Cmp    AL,'/'            ; Another switch?
  269.     Loopne    Sw2
  270.     Jcxz    Switch_Exit
  271.  
  272. Sw2a:    Lodsb                ; yes, get letter following
  273.     Dec    CX
  274.     Jle    Sw3            ; missing switch
  275.  
  276. Sw3:    Cmp    AL,'?'            ; Help?
  277.     Jne    Sw4
  278.     Mov    DX,Offset Help
  279.     Jmp    Exit
  280.  
  281. Sw4:    And    AL,0DFh            ; Make option uppercase
  282.     Cmp    AL,'A'            ; Attributes?
  283.     Jne    Sw5
  284.     Or    DH,ByAttr
  285. Sw5:    Cmp    AL,'B'            ; Brief?
  286.     Jne    Sw6
  287.     Or    DL,ByBrief
  288. Sw6:    Cmp    AL,'C'            ; Clear?
  289.     Jne    Sw7
  290.     Or    DH,ByClear
  291.     Call    Cls
  292. Sw7:    Cmp    AL,'D'            ; Date?
  293.     Jne    Sw8
  294.     Or    DH,ByDate
  295. Sw8:    Cmp    AL,'X'            ; Ext?
  296.     Jne    Sw9
  297.     Or    DH,ByExt
  298. Sw9:    Cmp    AL,'P'            ; Paths?
  299.     Jne    Sw10
  300.     Or    DL,ByPath
  301. Sw10:    Cmp    AL,'S'            ; Size?
  302.     Jne    Sw11
  303.     Or    DH,BySize
  304. Sw11:    Cmp    AL,'H'            ; Hidden?
  305.     Jne    Sw12
  306.     Or    DH,ByHide
  307. Sw12:    Cmp    AL,'M'            ; Modified only
  308.     Jne    Sw12b
  309.     Or    DL,ByMod
  310. Sw12b:    Cmp    AL,'W'            ; Wait when screen fills?
  311.     Jne    Sw12c
  312.     Or    DL,ByWait
  313. Sw12c:    Cmp    AL,'F'            ; Sort by filename?
  314.     Jne    Sw12d
  315.     Or    DH,ByName
  316. Sw12d:    Cmp    AL,'N'            ; No sorting?
  317.     Jne    Sw13
  318.     And    DH,0FFh-ByName-ByExt-BySize-ByDate
  319.  
  320. Sw13:    Jmp    Sw2            ; Try for another option
  321.  
  322. Switchs    Endp
  323.     Page
  324. ;
  325. ;    Copy command parameters
  326.  
  327. GetParm    Proc    Near
  328.     Mov    SI,82h            ;Command tail
  329.     Mov    DI,Offset ParmDir    ; goes after d:\
  330.     Sub    CX,CX
  331.     Or    CL,Byte    Ptr -2[SI]    ; any parmeters?
  332.     Jz    Parm9            ; no, use defaults
  333.  
  334. Parm0:    Cmp    Byte Ptr 1[SI],':'    ;Drive specified?
  335.     Jne    Parm1
  336.     Mov    DI,Offset ParmDr
  337.  
  338. Parm1:    Lodsb                ;Skip leading blanks
  339.     Cmp    AL,' '
  340.     Jne    Parm3
  341.     Loope    Parm1
  342.     Jcxz    Parm9
  343. Parm2:    Lodsb                ;Copy d:\path\fname.ext
  344. Parm3:    Cmp    AL,CR            ; end of string?
  345.     Je    Parm9
  346.     Cmp    AL,' '            ; end of operand?
  347.     Jbe    Parm9
  348.     Cmp    AL,','
  349.     Je    Parm9
  350.     Stosb
  351.     Loop    Parm2
  352.  
  353. Parm9:    And    ParmDr,0DFh        ;Upper case drive parm
  354.     Mov    DrPtr,DI        ;Save ptr to parm end
  355.     Mov    AL,ParmDr
  356.     Mov    OrigDr,AL
  357.     Mov    RootDir,AL
  358.     Ret
  359. GetParm    Endp
  360.     Page
  361. ;
  362. ;    Get volume label and disk free space
  363.  
  364. GetVol    Proc    Near
  365.     Mov    DL,ParmDr        ; Get drive letter
  366.     Sub    DL,64            ; and make it a    number
  367.     Mov    DriveNr,DL
  368.     Mov    SI,Offset OrigDir+1    ; Save current path name
  369.     Mov    AH,GETPATH
  370.     Int    21h
  371.  
  372.     Mov    AL,0            ; Get end of path name
  373.     Mov    DI,Offset OrigDir
  374.     Mov    CX,67
  375.     Repne    Scasb
  376.     Sub    DI,2
  377.     Mov    OrigPtr,DI
  378.  
  379.     Cmp    OrigDir+1,0        ; Already in root?
  380.     Je    Getvl3            ; yes, no chdir    needed
  381.     Inc    OrigPtr
  382.     Mov    DX,Offset RootDir    ; no, point to root directory
  383.     Mov    AH,CHDIR
  384.     Int    21h
  385.     Jc    Getvl9
  386.  
  387. Getvl3:    Mov    DX,Offset ExtFCB    ;Search    for volume entry
  388.     Mov    AH,11h
  389.     Int    21h
  390.  
  391.     Or    AL,AL            ;Any found?
  392.     Jnz    Getvl4            ; no, tough
  393.     Mov    CX,11            ; yes, copy it to heading
  394.     Mov    SI,Offset DTA+8
  395.     Mov    DI,Offset VolName
  396.     Repz    Movsb
  397.  
  398. Getvl4:    Cmp    OrigDir+1,0        ; Need to restore curdir?
  399.     Je    Getvl9
  400.     Mov    DX,Offset OrigDr    ; Back to current dir
  401.     Mov    AH,CHDIR
  402.     Int    21h
  403.  
  404. Getvl9:                ; Get disk free    space
  405.     Mov    DL,ParmDr        ; Current drive    letter
  406.     Sub    DL,64            ;  as a    number
  407.     Mov    AH,DSKSPC        ; Get free space
  408.     Int    21h
  409.     Cmp    AX,0FFFFh        ; Valid?
  410.     Je    Getvl10            ; no, skip it
  411.     Mul    CX            ;  Bytes per cluster
  412.     Mul    BX            ;  Total free
  413.     Mov    SI,Offset NrSize    ; Point    to msg
  414.     Call    Format
  415. Getvl10:
  416.     Ret
  417. Getvol    Endp
  418.  
  419.     Page
  420. ;
  421. ;    Set search criteria
  422.  
  423. SetArg    Proc    Near
  424. Set1:    Mov    BP,Offset DTA        ;First DTA
  425.     Mov    BX,Offset Search    ;Search    arument    entries
  426.  
  427.     Mov    AX,Word    Ptr ParmDr    ;Set search drive
  428.     Lea    DI,[BX].ArgDriv
  429.     Stosw
  430.     Mov    CX,OrigPtr        ;Set search path
  431.     Mov    SI,Offset OrigDr+2    ; from original    path
  432.     Sub    CX,SI
  433.  
  434. Set2:    Cmp    ParmDir,0        ;Is parm a path    or filespec
  435.     Je    Set4a            ; none,    append global to orig
  436.     Mov    DX,Offset ParmDr
  437.     Mov    AH,CHDIR
  438.     Int    21h            ;Is parm a valid path name?
  439.     Jnc    Set3            ; yes, leave criteria alone
  440.  
  441.     Jcxz    Set2a
  442.     Rep    Movsb
  443. Set2a:    Mov    SI,Offset ParmDir    ; no, add filespec as criteria
  444.     Mov    CX,DrPtr
  445.     Sub    CX,SI
  446.     Rep    Movsb
  447.     Push    DI
  448.     Jmp    Short Set7
  449.  
  450. Set3:    Mov    DX,Offset OrigDr    ;Restore path
  451.     Mov    AH,CHDIR
  452.     Int    21h
  453.  
  454. Set4:    Mov    SI,Offset ParmDir    ;Add parm path
  455.     Mov    CX,DrPtr
  456.     Sub    CX,SI
  457. Set4a:    Jcxz    Set5
  458.     Rep    Movsb
  459.  
  460. Set5:    Mov    SI,Offset AnyName    ;Add global search arg
  461.     Cmp    Byte Ptr -1[DI],'\'    ;Already have delimiter?
  462.     Jne    Set6
  463.     Dec    DI            ; yes, overlay it
  464. Set6:    Mov    CX,15
  465.     Push    DI
  466.     Rep    Movsb
  467. Set7:    Pop    CX
  468.     Lea    SI,[BX].ArgDriv
  469.     Sub    CX,SI
  470.     Mov    DI,Offset Titles
  471.     Rep    Movsb
  472.     Mov    Byte Ptr [DI],Stopper
  473.  
  474. Set10:    Ret
  475. SetArg    Endp
  476.     Page
  477. ;
  478. ;    Obtain directory table
  479.  
  480. Alloc    Proc    Near
  481.     Mov    DX,SP            ; Upper    segment    limit
  482.     Sub    DX,128            ; less stack size
  483.     And    DX,0FFF0h        ; to paragraph boundary
  484.     Mov    AX,Offset Table        ; lower    memory limit
  485.     And    AX,0FFF0h        ; to paragraph boundary
  486.     Add    AX,16
  487.     Mov    NxtDir,AX        ; as table address
  488.     Mov    PtrDir,AX
  489.     Sub    DX,AX            ; to bytes available
  490.     Mov    CL,6            ; into 64-byte entries
  491.     Shr    DX,CL            ; to hold directory data
  492.     Mov    MaxDir,DX
  493.     Mov    CL,4            ;Convert table offset
  494.     Shr    AX,CL            ; to a segment address
  495.     Mov    CX,CS
  496.     Add    CX,AX
  497.     Mov    SegDir,CX
  498.     Ret
  499. Alloc    Endp
  500.     Page
  501. ;
  502. ;    Build table of directory entries
  503.  
  504. GetDir    Proc    Near
  505.     Push    BP            ;Ptr to    DTA
  506.     Push    BX            ;Ptr to    search are
  507.  
  508. ; Set DTA for current nesting level
  509.     Mov    DX,BP            ;Data transfer area
  510.     Mov    AH,SETDTA        ;Set DTA
  511.     Int    21h
  512.  
  513. ; Set search criteria for this level
  514.     Mov    DX,BX            ;Search    criteria
  515.     Sub    CX,CX            ;Directory options
  516.     Mov    CL,DirMask
  517.     Mov    AH,4Eh            ;Find first matching entry
  518.     Int    21h
  519.  
  520. ; Examine directory entry just returned
  521. Get1:    Or    AL,AL
  522.     Jnz    GotDir            ;Not found, quit looking.
  523.     Cmp    Byte Ptr [BP].DtaAttr,10h
  524.     Jne    Get3            ;Is it a sub-dir?
  525.     Cmp    Byte Ptr [BP].DtaName,'.'
  526.     Je    Get4            ;May be    <DIR> entry
  527.  
  528.     Call    Writer
  529.  
  530. ; Build    parms for sub-dir search
  531.     Lea    DX,[BP].DtaName        ;Save ptr to found name
  532.     Lea    SI,[BX].ArgDriv        ;Point to current arg
  533.     Add    BP,Dta_Len        ;Next DTA
  534.     Add    BX,Arg_Len        ;Next search arg
  535.  
  536. ; Copy previous    arg as next search arg
  537.     Mov    CX,64            ;Maximum length
  538.     Lea    DI,[BX].ArgDriv        ;Point to new search arg
  539. Get6:    Lodsb
  540.     Cmp    AL,'?'            ;Used global name?
  541.     Je    Get9            ; yes, single nest
  542.     Cmp    AL,0            ;End of    dir name?
  543.     Je    Get5            ; yes, append wild cards
  544.     Stosb
  545.     Loop    Get6            ;Continue copying
  546.  
  547. ; Add sub-dir name to search arg
  548. Get9:    Mov    SI,DX            ;Saved ptr to found name
  549. Get8:    Lodsb
  550.     Cmp    AL,0            ;End of    DIR name?
  551.     Je    Get5            ; yes, append wild cards
  552.     Stosb                ; no, add to arg
  553.     Loop    Get8            ;Continue copying fname
  554.  
  555. Get5:    Mov    SI,Offset AnyName    ;Append    wild cards
  556.     Rep    Movsb
  557.  
  558.     Call    GetDir            ;Search    the sub-dir
  559.     Sub    BX,Arg_Len        ; restore arg
  560.     Sub    BP,Dta_Len        ; and DTA
  561.  
  562. ; Restore DTA to find next matching entry
  563.     Mov    DX,BP            ;Data transfer area
  564.     Mov    AH,SETDTA        ;Set DTA
  565.     Int    21h
  566.     Jmp    Short Get4
  567.  
  568. Get3:    Call    Writer            ;Add the entry
  569.  
  570. Get4:    Mov    CX,12            ;Clear found name
  571.     Mov    SI,Offset Blanks
  572.     Lea    DI,[BP].DtaName        ;Point to file name area
  573.     Rep    Movsb
  574.  
  575.     Mov    AH,4Fh            ;Search    for next file
  576.     Mov    DX,BP
  577.     Int    21h
  578.     Jmp    Get1            ;Loop for next one
  579.  
  580. GotDir:    Pop    BX            ;Restore arg
  581.     Pop    BP            ; and DTA
  582.     Ret
  583. GetDir    Endp
  584.     Page
  585. ;
  586. ;    Add directory entry to table
  587.  
  588. Writer    Proc    Near
  589.     Push    CX
  590.     Push    BP
  591.     Push    DI
  592.     Push    SI
  593.  
  594.     Mov    CX,Tbl_Len        ;Initialize table entry
  595.     Mov    SI,Offset Model
  596.     Mov    DI,Offset Entry
  597.     Rep    Movsb
  598.  
  599.     Mov    AL,[BP].DtaAttr        ;Copy file attributes
  600.     Mov    Entry.TblAttr,AL
  601.     Test    Flags2,ByMod        ;Just modified files?
  602.     Jz    Writer0            ; no, add all
  603.     Test    AL,10h            ; yes, pass subdirs
  604.     Jnz    Writer0
  605.     Test    AL,20h            ; is it    modified tho?
  606.     Jnz    Writer0            ; yes, add the entry
  607.     Jmp    Write1            ; no, exit
  608.  
  609. Writer0:
  610.     Call    GetDate            ;Format    date
  611.     Call    GetTime            ; time
  612.     Call    GetSize            ; bytes
  613.  
  614.     Lea    SI,[BP].DtaName        ;Copy file name
  615.     Lea    DI,Entry.TblName
  616.     Mov    CX,12
  617. Writea:    Lodsb
  618.     Cmp    AL,0
  619.     Je    Writec
  620.     Cmp    AL,'.'            ; separate extension
  621.     Je    Writeb
  622.     Stosb
  623.     Loop    Writea
  624. Writeb:    Jcxz    Writec
  625.     Lea    DI,Entry.TblName+8
  626. Writed:    Stosb
  627.     Lodsb
  628.     Cmp    AL,0
  629.     Je    Writec
  630.     Loop    Writed
  631.  
  632. Writec:    Lea    DI,Entry.TblPath    ;Copy path name
  633.     Lea    SI,[BX].ArgName
  634.     Mov    CX,Size    TblPath
  635. Writc1:    Cmp    Byte Ptr 1[SI],'?'    ; Wildcard part?
  636.     Je    Writc2            ; yes, have name
  637.     Lodsb
  638.     Stosb
  639.     Loop    Writc1
  640.  
  641. Writc2:
  642.     Lea    SI,Entry.TblName
  643.     Test    Entry.TblAttr,10h    ;Subdirectory?
  644.     Jnz    Writc3            ; yes, copy path name
  645.     Jcxz    Writee            ; no, pad with blanks
  646.     Mov    SI,Offset Blanks
  647.     Rep    Movsb
  648.     Jmp    Writee
  649.  
  650. Writc3:    Cmp    CL,12            ; Max subdir name length
  651.     Jbe    Writc4            ; to be    copied
  652.     Mov    CL,12
  653. Writc4:    Rep    Movsb
  654.  
  655. Writee:    Mov    CX,NumDir        ;Number    of table entries
  656.     Cmp    CX,MaxDir        ; is table full?
  657.     Jae    Write1            ; yes, skip it
  658.     Mov    DI,NxtDir        ;Offset    to next    table entry
  659.     Mov    SI,Offset Entry        ; copy table stuff
  660.     Mov    CX,Tbl_Len
  661.     Rep    Movsb
  662.     Inc    NumDir            ;Incr entry count
  663.     Add    NxtDir,Tbl_Len        ; and next ptr
  664.  
  665. Write1:    Pop    SI
  666.     Pop    DI
  667.     Pop    BP
  668.     Pop    CX
  669.     Ret
  670. Writer    Endp
  671.     Page
  672. ;
  673. ;    Print file information
  674.  
  675. Print    Proc    Near
  676.     Cmp    NumDir,1        ;Just one file?
  677.     Ja    PrintT            ; no, two up heading
  678.     Mov    Word Ptr Titled,0A0Dh
  679.     Mov    Titled+2,Stopper
  680. PrintT:    Mov    DX,Offset Titlea    ;Top titles
  681.     Call    PrintS
  682.     Mov    DX,Offset Titleb    ;Subdir    name
  683.     Call    PrintS
  684.     Mov    DX,Offset Titlec    ;Headings
  685.     Call    PrintS
  686.  
  687.     Mov    AX,CS            ;Set extra seg
  688.     Mov    ES,AX
  689.     Mov    AX,PtrDir        ;Offset    to table
  690.     Mov    NxtDir,AX        ; as current entry
  691.     Mov    AX,NumDir        ;Compute offset
  692.     Inc    AX            ; to second half
  693.     Shr    AX,1
  694.     Mov    CL,6
  695.     Shl    AX,CL
  696.     Mov    CX,NumDir        ;Number    of entries
  697.     Or    CX,CX
  698.     Jz    Print7
  699.     Inc    CX            ; in each half
  700.     Shr    CX,1
  701.  
  702. Print_Next:
  703.     Call    Print0            ;Left side
  704.     Push    [NxtDir]
  705.     Add    NxtDir,AX
  706.     Call    Print0            ;Right side
  707.     Pop    [NxtDir]
  708.     Add    NxtDir,Tbl_Len        ; point    to next    entry
  709.  
  710.     Test    Flags2,ByWait        ;Wait for screen full?
  711.     Jz    PrintW1
  712.     Inc    Linecnt            ; yes, bump line count
  713.     Cmp    Linecnt,20        ;Full now?
  714.     Jbe    PrintW1            ; no, continue
  715.     Call    Waitkey
  716. PrintW1:
  717.     Loop    Print_Next
  718.  
  719. Print7:    Ret
  720. Print    Endp
  721.  
  722. Print0    Proc    Near
  723.     Push    AX
  724.     Push    CX
  725.     Push    DI
  726.     Inc    Count            ;Number    of files
  727.     Mov    AX,Count
  728.     Cmp    AX,NumDir        ;Done em all?
  729.     Jbe    Print1
  730.     Dec    Count
  731.     Jmp    Print9
  732.  
  733. Print1:
  734.     Mov    BP,NxtDir        ;Offset    to table entry
  735.     Mov    CL,Byte    Ptr [BP].TblAttr
  736.     Lea    DI,Byte    Ptr [BP].TblFatr
  737.     Test    CL,32            ;Archived?
  738.     Jnz    Print2
  739.     Mov    AL,'A'
  740.     Stosb
  741.  
  742. Print2:    Test    CL,4            ;System?
  743.     Jz    Print3
  744.     Mov    AL,'S'
  745.     Stosb
  746.  
  747. Print3:    Test    CL,2            ;Hidden?
  748.     Jz    Print4
  749.     Mov    AL,'H'
  750.     Stosb
  751.  
  752. Print4:    Test    CL,1            ;Read only?
  753.     Jz    Print5
  754.     Mov    AL,'R'
  755.     Stosb
  756.  
  757. Print5:    Test    CL,10h            ;Sub directory?
  758.     Jz    Print5a
  759.     Lea    DI,[BP].TblFatr-1    ; yes, special display
  760.     Mov    SI,Offset Subdir
  761.     Mov    CX,4
  762.     Rep    Movsb
  763.  
  764. Print5a:
  765.     Test    Flags2,ByPath        ;Doing all paths?
  766.     Jz    Print6
  767.     Cmp    [BP].TblPath+1,'?'    ;Nested    entry?
  768.     Je    Print6            ; no, as-is
  769.     Mov    [BP].TblFatr-1,'-'    ; yes, flag it in display
  770.  
  771. Print6:    Lea    SI,[BP].TblDate        ;Reformat date
  772.     Mov    DI,Offset OldDate
  773.     Mov    CX,8
  774.     Rep    Movsb
  775.  
  776.     Lea    DI,[BP].TblDate
  777.     Mov    AX,Word    Ptr OldDate+3
  778.     Stosw
  779.     Mov    AL,"/"
  780.     Stosb
  781.     Mov    AX,Word    Ptr OldDate+6
  782.     Stosw
  783.     Mov    AL,"/"
  784.     Stosb
  785.     Mov    AX,Word    Ptr OldDate
  786.     Stosw
  787.  
  788.     Cmp    [BP].TblExt,' '        ;Any extension?
  789.     Jne    Print8            ; yes, leave the dot
  790.     Mov    [BP].TblExt-1,' '    ; no, rid it
  791.  
  792. Print8:    Lea    DX,[BP].TblName
  793.     Mov    Byte Ptr [BP].TblCtl,' '
  794.     Mov    Byte Ptr [BP+1].TblCtl,Stopper
  795.     Mov    NrMsg+1,Lf
  796.     Test    Count,1            ;Right side?
  797.     Jnz    Print8a
  798.     Mov    NrMsg+1,Cr
  799.     Mov    Word Ptr [BP].TblCtl,0a0dh
  800. Print8a:
  801.     Call    PrintS            ;Display an entry
  802.  
  803. Print9:    Pop    DI
  804.     Pop    CX
  805.     Pop    AX
  806.     Ret
  807. Print0    Endp
  808.  
  809.     Page
  810. ;
  811. ;    Pause at end of    screen for any key
  812.  
  813. Waitkey    Proc    Near
  814.     Push    AX
  815.     Push    BX
  816.     Push    CX
  817.     Push    DX
  818.  
  819.     Mov    Linecnt,0        ; reset    counter
  820.     Mov    AH,2
  821.     Mov    DX,1847h
  822.     Sub    BX,BX
  823.     Int    10h
  824.  
  825.     Mov    DX,Offset More        ; ask for more
  826.     Call    PrintS
  827.  
  828.     Mov    AH,0            ; wait for a key
  829.     Int    16h
  830.  
  831.     Test    Flags,ByClear        ; Clear    screen each time?
  832.     Jnz    Waitkeyc
  833.     Mov    DX,Offset Newline
  834.     Call    PrintS
  835.     Jmp    Waitkeyx
  836.  
  837. Waitkeyc:
  838.     Call    Cls
  839.  
  840.     Mov    DX,Offset Titlea    ;Top titles
  841.     Call    PrintS
  842.     Mov    DX,Offset Titleb    ;Subdir    name
  843.     Call    PrintS
  844.     Mov    DX,Offset Titlec    ;Headings
  845.     Call    PrintS
  846.  
  847. Waitkeyx:
  848.     Pop    DX
  849.     Pop    CX
  850.     Pop    BX
  851.     Pop    AX
  852.     Ret
  853. Waitkey    Endp
  854.     Page
  855. ;
  856. ;    Format the date
  857.  
  858. GetDate    Proc    Near            ;Format    the date
  859.     Mov    AX,Word    Ptr [BP].DtaDate
  860.     Mov    DI,Offset Entry.TblDate
  861.     Or    AX,AX            ;Is it zero?
  862.     Jz    GotDate
  863.     Push    AX            ;Save date
  864.     And    AX,Mask    Yr        ;Get year part
  865.     Mov    CL,Yr            ;Bits to shift
  866.     Call    Cnvrt
  867.     Or    AL,'8'            ;Adjust    for base year
  868.     Stosw
  869.     Mov    AL,'-'
  870.     Stosb
  871.  
  872.     Pop    AX            ;Get the date back
  873.     Push    AX            ;Save it
  874.     And    AX,Mask    Mo        ;Get month part
  875.     Mov    CL,Mo            ;Bits to shift
  876.     Call    Cnvrt2
  877.     Stosw
  878.     Mov    AL,'/'
  879.     Stosb
  880.  
  881.     Pop    AX            ;Get the date back
  882.     And    AX,Mask    Dy        ;Get day part
  883.     Mov    CL,Dy            ;Bits to shift
  884.     Call    Cnvrt
  885.     Stosw
  886. GotDate:Ret
  887. GetDate    Endp
  888.  
  889. ;    Format the time
  890.  
  891. GetTime    Proc    Near            ;Format    the date
  892.     Mov    AX,Word    Ptr [BP].DtaTime
  893.     Lea    DI,Entry.TblTime
  894.     Or    AX,AX            ;It is zero?
  895.     Jz    GotTime
  896.     Push    AX            ;Save date
  897.     And    AX,Mask    Hour        ;Get hour part
  898.     Mov    CL,Hour            ;Bits to shift
  899.     Shr    AX,CL
  900.     Call    Cnvrt1
  901.     Stosw
  902.     Mov    AL,':'
  903.     Stosb
  904.  
  905. GT3:    Pop    AX            ;Get the time back
  906.     And    AX,Mask    Min        ;Get min part
  907.     Mov    CL,Min            ;Bits to shift
  908.     Call    Cnvrt
  909.     Stosw
  910. GotTime:Ret
  911. GetTime    Endp
  912.  
  913. Cnvrt2    Proc    Near            ;Convert to ASCII
  914.     Call    Cnvrt
  915.     Cmp    AL,'0'            ;Suppress leading zero
  916.     Jne    Cnvrtd
  917.     Mov    AL,' '
  918.     Ret
  919.  
  920. Cnvrt:    Shr    AX,CL
  921. Cnvrt1:    Aam                ;Make AL into BCD
  922.     Or    AX,'00'            ; and to ASCII
  923.     Xchg    AL,AH
  924. Cnvrtd:    Ret
  925. Cnvrt2    Endp
  926.     Page
  927. ;
  928. ;    Format the size
  929.  
  930. GetSize    Proc    Near
  931.     Push    BP            ; Ptr to Dta entry
  932.     Push    BX
  933.     Mov    AX,Word    Ptr [BP].DtaSize
  934.     Add    NumByte+2,AX
  935.     Mov    DX,Word    Ptr [BP].DtaSize+2
  936.     Adc    NumByte,DX
  937.     Lea    SI,Entry.TblSize    ;Target    offset
  938.     Call    Format            ;Format    double word
  939.     Pop    BX
  940.     Pop    BP
  941.     Ret
  942. GetSize    Endp
  943.  
  944.     Page
  945. ;
  946. ; Ripped from sdir.asm.    How does this work?
  947.  
  948. Ddptr    Dw    0
  949.  
  950. Format    Proc    Near    ;Formats a 32 bit integer in DX:AX
  951.     Push    BP    ; to DS:SI
  952.     Push    BX
  953.     Push    DI
  954.     Push    SI
  955.     Mov    Ddptr,SI    ;addr of target    field
  956.     Mov    DI,DX        ;routine uses di:si
  957.     Mov    SI,AX
  958.     Call    Printdd
  959.     Pop    SI
  960.     Pop    DI
  961.     Pop    BX
  962.     Pop    BP
  963.     Ret
  964.  
  965. Printdd:
  966.     Xor    AX,AX        ;zero out the
  967.     Mov    BX,AX        ; working
  968.     Mov    BP,AX        ; registers.
  969.     Mov    CX,32        ;# bits    of precision
  970. J1:    Shl    SI,1
  971.     Rcl    DI,1
  972.     Xchg    BP,AX
  973.     Call    J6
  974.     Xchg    BP,AX
  975.     Xchg    BX,AX
  976.     Call    J6
  977.     Xchg    BX,AX
  978.     Adc    AL,0
  979.     Loop    J1
  980.     Mov    CX,1710h
  981.     Mov    AX,BX
  982.     Call    J2
  983.     Mov    AX,BP
  984. J2:    Push    AX
  985.     Mov    DL,AH
  986.     Call    J3
  987.     Pop    DX
  988. J3:    Mov    DH,DL
  989.     Shr    DL,1        ;move high
  990.     Shr    DL,1        ; nibble to
  991.     Shr    DL,1        ; the low
  992.     Shr    DL,1        ; position.
  993.     Call    J4
  994.     Mov    DL,DH
  995. J4:    And    DL,0fh        ;mask low nibble
  996.     Jz    J5        ;if not    zero
  997.     Sub    CL,CL
  998. J5:    Dec    CH
  999.     And    CL,CH
  1000.     Or    DL,'0'        ;fold in ascii zero
  1001.     Sub    DL,CL
  1002.     Mov    BX,Ddptr
  1003.     Mov    [BX],DL        ;ptr to    next target field
  1004.     Inc    Ddptr
  1005.     Ret
  1006.  
  1007. J6:    Adc    AL,AL
  1008.     Daa
  1009.     Xchg    AL,AH
  1010.     Adc    AL,AL
  1011.     Daa
  1012.     Xchg    AL,AH
  1013.     Ret
  1014.  
  1015.  
  1016. Format    Endp
  1017.     Page
  1018. ;
  1019. ;    Print String like INT 21H function 9
  1020.  
  1021. PrintS    Proc    Near            ; DX has offset    to string
  1022.     Push    SI            ;  ending in char x'FF'
  1023.     Push    BX
  1024.     Push    CX
  1025.     Mov    SI,DX            ; Ptr to string    text
  1026.     Sub    CX,CX            ; Overall text length
  1027. PS1:    Lodsb
  1028.     Cmp    AL,Stopper        ; Ending hex FF?
  1029.     Je    PS9
  1030.     Inc    CX
  1031.     Jmp    Short PS1
  1032.  
  1033. PS9:
  1034.     Mov    BX,1            ; Standard output device
  1035.     Mov    AH,40h            ;  to write to
  1036.     Int    21h
  1037.  
  1038.     Pop    CX            ; Recover registers
  1039.     Pop    BX
  1040.     Pop    SI
  1041.     Ret
  1042. PrintS    Endp
  1043.  
  1044.  
  1045. Cls    Proc    Near            ; Clear    screen
  1046.     Push    AX
  1047.     Push    BX
  1048.     Push    CX
  1049.     Push    DX
  1050.     Push    SI
  1051.  
  1052.     Mov    AX,600h            ; Scroll all lines
  1053.     Sub    CX,CX            ;  upper left
  1054.     Mov    DX,184Fh        ;  lower right
  1055.     Mov    BL,_Page        ;  video page
  1056.     Mov    BH,_Attr        ;  attribute
  1057.     Int    10h            ; Video    I/O
  1058.  
  1059.     Mov    BL,_Attr        ; Set cursor position
  1060.     Mov    BH,_Page
  1061.     Sub    DX,DX            ;  to 1,1
  1062.     Mov    AH,2
  1063.     Int    10h
  1064.  
  1065.     Pop    SI
  1066.     Pop    DX
  1067.     Pop    CX
  1068.     Pop    BX
  1069.     Pop    AX
  1070.     Ret
  1071. Cls    Endp
  1072.  
  1073.     Page
  1074. ;
  1075. ;    Format current date and    time
  1076.  
  1077. Clock    Proc    Near
  1078.     Push    AX
  1079.     Push    BX
  1080.     Push    CX
  1081.     Push    DX
  1082.  
  1083.     Mov    AH,2Ah            ;Get date
  1084.     Int    21h
  1085.     Sub    CX,1900            ; last two digits
  1086.     Mov    AX,CX            ;Make readable
  1087.     Call    Cnvrt1            ;Convert to ASCII
  1088.     Mov    Word Ptr Year,AX
  1089.     Xchg    AL,DH            ;Get month
  1090.     Call    Cnvrt1            ;Convert to ASCII
  1091.     Mov    Word Ptr Month,AX
  1092.     Xchg    AL,DL            ;Get day
  1093.     Call    Cnvrt1            ;Convert to ASCII
  1094.     Mov    Word Ptr Day,AX
  1095.  
  1096.     Mov    AH,2Ch            ;Get time
  1097.     Int    21h
  1098.     Xchg    AL,CH            ;Get hours
  1099.     Call    Cnvrt1            ;Convert to ASCII
  1100.     Mov    Word Ptr Hours,AX
  1101.     Xchg    AL,CL            ;Get minutes
  1102.     Call    Cnvrt1            ;Convert to ASCII
  1103.     Mov    Word Ptr Mins,AX
  1104.     Xchg    AL,DH            ;Get seconds
  1105.     Call    Cnvrt1            ;Convert to ASCII
  1106.     Mov    Word Ptr Secs,AX
  1107.  
  1108.     Pop    DX
  1109.     Pop    CX
  1110.     Pop    BX
  1111.     Pop    AX
  1112.     Ret
  1113. Clock    Endp
  1114.     Page
  1115. ;
  1116. ;    Shell-Metzger Sort of 64-byte table records
  1117.  
  1118. Sort    Proc    Near
  1119.     Push    DS            ;Save seg regs
  1120.     Push    ES
  1121.  
  1122. ;    Set sort options
  1123.  
  1124.     Sub    BX,BX            ;Offset    to key
  1125.     Mov    BL,Offset TblPath
  1126.     Test    Flags,BySize
  1127.     Jz    Sort1
  1128.     Mov    BL,Offset TblSize    ;Sort by size
  1129. Sort1:    Test    Flags,ByDate
  1130.     Jz    Sort2
  1131.     Mov    BL,Offset TblDate    ;Sort by date/time
  1132. Sort2:    Test    Flags,ByExt
  1133.     Jz    Sort3
  1134.     Mov    BL,Offset TblExt
  1135.  
  1136. ;    Initialize sort    parameters
  1137.  
  1138. Sort3:    Mov    CX,NumDir        ;Number    of entries
  1139.     Mov    NumRec,CX
  1140.     Mov    KeyPtr,BX
  1141.  
  1142.     Mov    DX,64            ;Length    of key
  1143.     Sub    DX,BX
  1144.     Mov    KeyLen,DX
  1145.     Mov    ES,SegDir        ;Seg addr of table
  1146.     Mov    AX,ES            ;Save array addr
  1147.     Sub    AX,4            ; adjust for indexing
  1148.     Mov    Base,AX
  1149.  
  1150. ;    Sort 64-byte entries
  1151.  
  1152.     Mov    Loc,CX            ; Loc=NumRecs
  1153.  
  1154. Check:    Cmp    Loc,1            ; IF Loc<=1 THEN
  1155.     Jg    Check1            ; GOTO SORTED
  1156.     Jmp    Sorted
  1157.  
  1158. Check1:    Mov    AX,Loc
  1159.     Sar    AX,1            ; Loc=2*(Loc/4)+1
  1160.     Or    AX,1
  1161.     Mov    Loc,AX
  1162.  
  1163.     Mov    AX,NumRec        ; Limit=NumRec-Loc
  1164.     Sub    AX,Loc
  1165.     Mov    Limit,AX
  1166.  
  1167.     Mov    Incr,0            ; Incr=0
  1168.  
  1169. Again:    Inc    Incr            ; Incr=Incr+1
  1170.  
  1171.     Mov    AX,Incr            ; IF Incr>Limit    THEN GOTO CHECK
  1172.     Cmp    AX,Limit
  1173.     Jg    Check
  1174.  
  1175.     Shl    AX,1
  1176.     Shl    AX,1
  1177.     Mov    Index1,AX        ; Index1=Incr
  1178.  
  1179.     Mov    Index2,AX        ; Index2=Index1+Loc
  1180.     Mov    AX,Loc
  1181.     Shl    AX,1            ; times    2
  1182.     Shl    AX,1            ; times    4
  1183.     Add    Index2,AX
  1184.  
  1185. Comp:    Mov    AX,Index1        ; IF array(Index1)<=array(Index2)
  1186.     Add    AX,Base
  1187.     Mov    ES,AX
  1188.     Mov    Ptr1,AX
  1189.     Mov    DI,KeyPtr
  1190.  
  1191.     Mov    AX,Index2        ; THEN GOTO AGAIN
  1192.     Add    AX,Base
  1193.     Mov    Ptr2,AX
  1194.     Mov    SI,KeyPtr
  1195.     Mov    CX,CS:KeyLen
  1196.  
  1197.     Push    DS
  1198.     Mov    DS,AX
  1199.     Repe    Cmpsb
  1200.     Pop    DS
  1201.     Jae    Again
  1202.  
  1203. Swap:    Mov    BX,Ptr1            ; ELSE
  1204.     Mov    DX,Ptr2            ; TEMP=array(Index1)
  1205.  
  1206.     Mov    AX,CS
  1207.     Mov    ES,AX
  1208.     Mov    DI,Offset Temp
  1209.     Mov    CX,Tbl_Len
  1210.  
  1211.     Mov    DS,BX
  1212.     Sub    SI,SI
  1213.     Rep    Movsb
  1214.  
  1215.     Mov    ES,BX            ; array(Index1)=array(Index2)
  1216.     Mov    DS,DX
  1217.     Sub    DI,DI
  1218.     Sub    SI,SI
  1219.     Mov    CX,Tbl_Len
  1220.     Rep    Movsb
  1221.  
  1222.     Mov    AX,CS            ; array(Index2)=TEMP
  1223.     Mov    DS,AX
  1224.     Mov    SI,Offset Temp
  1225.     Mov    ES,DX
  1226.     Sub    DI,DI
  1227.     Mov    CX,Tbl_Len
  1228.     Rep    Movsb
  1229.  
  1230.     Mov    AX,Index1        ; Index2=Index1
  1231.     Mov    Index2,AX
  1232.  
  1233.     Mov    AX,Loc            ; Index1=Index1-Loc
  1234.     Shl    AX,1
  1235.     Shl    AX,1
  1236.     Sub    Index1,AX
  1237.  
  1238.     Jg    Comp            ; IF Index1>0 then GOTO    COMP
  1239.     Jmp    Again            ; ELSE GOTO AGAIN
  1240.  
  1241. Sorted:    Pop    ES            ;Recover register
  1242.     Pop    DS
  1243.     Ret
  1244. Sort    Endp
  1245.     Page
  1246. Help    Db    CR,LF,TAB,TAB,' -- LDIR Version 3.0 --- 4 June 86 --'
  1247.     Db    CR,LF,TAB,TAB,'  (c) Copyright Vernon D. Buerg 1986'
  1248.     Db    CR,LF
  1249.     Db    CR,LF,TAB,TAB,TAB,' Command syntax:'
  1250.     Db    CR,LF
  1251.     Db    CR,LF,TAB,TAB,'LDIR [d:][\path[fname[.ext]]] /?.../?'
  1252.     Db    CR,LF,TAB,TAB
  1253.     Db    CR,LF,TAB,TAB,'    /A   include Attributes'
  1254.     Db    CR,LF,TAB,TAB,'    /C   Clear screen first'
  1255.     Db    CR,LF,TAB,TAB,'    /D   sort by Date'
  1256. ;    Db    CR,LF,TAB,TAB,'    /F   sort by Filename (default)'
  1257.     Db    CR,LF,TAB,TAB,'    /H   include Hidden files'
  1258.     Db    CR,LF,TAB,TAB,'    /M   only Modified files'
  1259.     Db    CR,LF,TAB,TAB,'    /N   No sorting'
  1260.     Db    CR,LF,TAB,TAB,'    /P   include all Paths'
  1261.     Db    CR,LF,TAB,TAB,'    /S   sort by Size'
  1262.     Db    CR,LF,TAB,TAB,'    /W   Wait after screen full'
  1263.     Db    CR,LF,TAB,TAB,'    /X   sort by eXtension'
  1264.     Db    Stopper
  1265. ;    Db    CR,LF,TAB,TAB,'    /?   display usage syntax',Stopper
  1266.  
  1267.     Page
  1268. ;
  1269. ;    Data structures    and work areas
  1270.  
  1271. Entry    Equ    $            ;Print line
  1272.  
  1273. DTA    Equ    Entry+Tbl_Len        ;Disk transfer areas
  1274.  
  1275. Search    Equ    DTA + (Depth+1)*Dta_Len    ;Search    arguments
  1276.  
  1277. Table    Equ    Search + (Depth+1)*Arg_Len
  1278.  
  1279. Cseg    Ends
  1280.     End    Ldir
  1281.